GtkLabel: better treatment for selection with ellipsis
authorMatthias Clasen <mclasen@redhat.com>
Thu, 4 Sep 2014 02:18:49 +0000 (22:18 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 4 Sep 2014 02:23:08 +0000 (22:23 -0400)
This commit arranges things so that we treat an ellipsized
region like a single character for the purpose of selection
and cursor navigation.

https://bugzilla.gnome.org/show_bug.cgi?id=328449

gtk/gtklabel.c

index 9c9d09839508b75e1caa62d4168a35c9483599c5..3f549a047b511f1820aa8ba1b1c0fb242c4f5a2a 100644 (file)
@@ -5578,6 +5578,60 @@ gtk_label_select_region_index (GtkLabel *label,
   if (priv->select_info && priv->select_info->selectable)
     {
       GtkClipboard *clipboard;
+      gint s, e;
+
+      /* Ensure that we treat an ellipsized region like a single
+       * character with respect to selection.
+       */
+      if (anchor_index < end_index)
+        {
+          if (range_is_in_ellipsis_full (label, anchor_index, anchor_index + 1, &s, &e))
+            {
+              if (priv->select_info->selection_anchor == s)
+                anchor_index = e;
+              else
+                anchor_index = s;
+            }
+          if (range_is_in_ellipsis_full (label, end_index - 1, end_index, &s, &e))
+            {
+              if (priv->select_info->selection_end == e)
+                end_index = s;
+              else
+                end_index = e;
+            }
+        }
+      else if (end_index < anchor_index)
+        {
+          if (range_is_in_ellipsis_full (label, end_index, end_index + 1, &s, &e))
+            {
+              if (priv->select_info->selection_end == s)
+                end_index = e;
+              else
+                end_index = s;
+            }
+          if (range_is_in_ellipsis_full (label, anchor_index - 1, anchor_index, &s, &e))
+            {
+              if (priv->select_info->selection_anchor == e)
+                anchor_index = s;
+              else
+                anchor_index = e;
+            }
+        }
+      else
+        {
+          if (range_is_in_ellipsis_full (label, anchor_index, anchor_index, &s, &e))
+            {
+              if (priv->select_info->selection_anchor == s)
+                anchor_index = e;
+              else if (priv->select_info->selection_anchor == e)
+                anchor_index = s;
+              else if (anchor_index - s < e - anchor_index)
+                anchor_index = s;
+              else
+                anchor_index = e;
+              end_index = anchor_index;
+            }
+        }
 
       if (priv->select_info->selection_anchor == anchor_index &&
           priv->select_info->selection_end == end_index)